﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Product.Domain.Entity;
using Product.EntityFrameworkCore.PO;

namespace Product.EntityFrameworkCore.MapConfiguration
{
    public class SpuMapConfiguration : IEntityTypeConfiguration<SpuPo>
    {
        public void Configure(EntityTypeBuilder<SpuPo> builder)
        {
            builder.ToTable("t_spu");
            builder.HasKey("Id");
            builder.Property(e => e.Id).HasMaxLength(64).IsRequired();
            builder.Property(e => e.SpuName).HasMaxLength(100).IsRequired();
            builder.Property(e => e.BrandId).HasMaxLength(64).IsRequired();
            builder.Property(e => e.CategoryId).HasMaxLength(64).IsRequired();
            builder.Property(e => e.PicUrl).HasMaxLength(64).IsRequired();
            builder.Property(e => e.SalesStatus).HasMaxLength(10).IsRequired();
            builder.Property(e => e.Version).IsRequired();
            builder.HasMany(e => e.SkuList).WithOne().HasForeignKey(s => s.SpuId);
            builder.HasMany(e => e.SpecificationList).WithOne().HasForeignKey(s => s.SpuId);
            builder.HasOne(e => e.Category).WithOne().HasForeignKey<SpuPo>(e => e.CategoryId);
            builder.HasOne(e => e.Brand).WithOne().HasForeignKey<SpuPo>(e => e.BrandId);
        }
    }
}
